<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>

    <title>api 测试页面</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">



  	<script type="text/javascript">

  	        var G_TIMEOUT = 120000; // 10秒



  	      $(document).on("pagebeforeshow", function(event, data){

	  			  var selfUrl = window.location.href;
	  	  	      selfUrl = "http://localhost:2884/jsonrpc"; //selfUrl.substr(0, selfUrl.length-9);
	  	  	      // alert(selfUrl);

	  	  	      var initUrl = selfUrl + "jsonrpc";


	  	  	      var initParam = {"method":"login","data":{"account":"admin","password":"admin"}};
								initParam = JSON.stringify(initParam);

  	    		$("#url").val(initUrl);
  	    		$("#param").val(initParam);


  	          });


  	        // call api
  	        var callApi = function() {

  	        	$("#result").val("正在调用...");


  	        	var url = $("#url").val();

  	        	var pstr= $("#param").val();

  	        	var param = $.parseJSON(pstr);

  	        	ajaxPost(url, param, handleResponse);


  	        }

  	        var handleResponse = function(response) {
  	        	var str = JSON.stringify(response);

  	        	$("#result").val(str);

  	        }


  	        var handleError = function(ex) {

  	        	$("#result").val(ex);

  	        }



		  	var myConsoleLog = function(msg) {

		  		// console.log(msg);

		  	}


  	        // Post
		  	var ajaxPost = function(url, param, callback){

		  	  var data = param;

		  	  var data4log = JSON.stringify(data);

		  	myConsoleLog("ajaxPost start \n\t url=" + url + "\n\t post=" + data4log);

		  	  // サーバにsubmit
		  	  $.ajax({

								contentType: "application/json; charset=utf-8",
		  	        type    : "POST",
		  	        url     : url,
		  	        data    : data4log,
		  	        dataType: "json",
		  	        timeout : G_TIMEOUT,
		  	        success : function(response, ex){
		  	        	myConsoleLog("ajaxPost success!\t");

		  	          callback(response);
		  	        },
		  	        error   : function(request, status, ex){
		  	        	var err = "ajaxPost error!\t(status:"+status+", exception:" + ex + ")";
		  	        	handleError(err);
		  	        	myConsoleLog(err);
		  	        }
		  	  });

		  		myConsoleLog("ajaxPost end");
		  	};



  	</script>

  </head>

<body>

    <div id="test_page" data-role="page">

        <div data-role="header" data-position="fixed" data-fullscreen="false" data-tap-toggle="false" data-theme="c">

          <h3 id="idBld_PageTitle" class="head-tilte">JBiz API 测试页</h3>
        </div>

        <div class="css_listarea" data-role="content">


			<div style="width:800px;">
			url:
			<input type="text" id="url"  size="100" />
			</div>

			<div style="width:800px;">
			form param:
			<textarea id="param"  style="height:150px;" ></textarea>
			</div>

			<div style="width:300px;">
			:
			<input type="button" id="submit_btn"  value="提交"  onclick="callApi();" />
			</div>

			<br/>
			<br/>
			<hr/>

			<div>
				返回结果：

				<textarea id="result"  style="height:150px;" ></textarea>

			</div>

        </div>
    </div>



</body>
</html>
